package pl.edu.wsinf.lukaszwalczak.emailclient.pojo;

import java.io.Serializable;
import javax.persistence.Embeddable;
import javax.validation.constraints.Size;

@Embeddable
public class EmailAddress implements Serializable {

    @Size(max = 255)
    private String address;
    @Size(max = 300)
    private String personal;

    public EmailAddress() {
    }

    public EmailAddress(String address, String personal) {
        this.address = address != null ? address.toLowerCase() : null;
        this.personal = personal;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address != null ? address.toLowerCase() : null;
    }

    public String getPersonal() {
        return personal;
    }

    public void setPersonal(String personal) {
        this.personal = personal;
    }

    @Override
    public String toString() {
        String result = "";
        if (this.getPersonal() != null && !this.getPersonal().isEmpty()) {
            result = this.getPersonal();
            if (this.getAddress() != null) {
                result += " <" + this.getAddress() + ">";
            }
        } else if (this.getAddress() != null) {
            result = this.getAddress();
        }
        return result;
    }
}
